Skip to content

caddyhttp: reject HTTP listeners that use admin API port#7868

Open
DearRude wants to merge 7 commits into
caddyserver:masterfrom
DearRude:fix/caddyhttp-reject-admin-port
Open

caddyhttp: reject HTTP listeners that use admin API port#7868
DearRude wants to merge 7 commits into
caddyserver:masterfrom
DearRude:fix/caddyhttp-reject-admin-port

Conversation

@DearRude

@DearRude DearRude commented Jul 9, 2026

Copy link
Copy Markdown

Expose LocalAdminPort() so the HTTP app can detect listener addresses that conflict with the local admin endpoint during validation.

When admin is disabled, the check is skipped so HTTP servers may use the default admin port. When admin listens on a custom port, only that port is protected.

Fixes: #7053

Assistance Disclosure

The code was co-authored with Cursor. I manually tested the change and revised the implementation afterwards.

Expose LocalAdminPort() so the HTTP app can detect listener addresses
that conflict with the local admin endpoint during validation.

When admin is disabled, the check is skipped so HTTP servers may use
the default admin port. When admin listens on a custom port, only
that port is protected.

Fixes: caddyserver#7053

Signed-off-by: Ebrahim Nejati <ebrahim@nejati.net>
@CLAassistant

CLAassistant commented Jul 9, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

steadytao

This comment was marked as outdated.

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing only the numeric port is too broad because LocalAdminPort discards the admin listener's network and host. For example, an admin listener on 127.0.0.1:2019 does not necessarily conflict with an HTTP listener bound to a different concrete address on port 2019, and this also cannot represent Unix or abstract-socket admin listeners correctly. Could we preserve the complete resolved NetworkAddress and check actual listener overlap instead?

@DearRude

Copy link
Copy Markdown
Author

Could we preserve the complete resolved NetworkAddress and check actual listener overlap instead?

@steadytao I thought about this at first too. I decided to keep the simple check because checking the exact address makes the code complex and might confuse the user.

I will try to find a clean way to check the exact overlap using the NetworkAddress.

Adjusted related logic in the app validation to check for overlapping listener addresses with the admin API.

Added a new test to ensure non-overlapping admin addresses are allowed.

Fixes: caddyserver#7053

Signed-off-by: Ebrahim Nejati <ebrahim@nejati.net>
@DearRude

Copy link
Copy Markdown
Author

@steadytao Tell me if it's good so I can squash it afterwards

@DearRude
DearRude requested a review from steadytao July 11, 2026 10:29
@steadytao

Copy link
Copy Markdown
Member

Just a quick note that mentioning me multiple times will not make me any less busy then I am 😅 Additionally, it is the weekend currently. I will take a look but please keep in mind to be respectful in the future, I do believe my status should warn upon mentioning me that I will be slow to respond.

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is closer but the overlap helper still has incorrect wildcard, loopback, Unix-socket and network-family cases.

Comment thread listeners.go Outdated
Comment thread listeners.go
Comment thread listeners.go Outdated
Comment thread modules/caddyhttp/app_test.go Outdated
Refactored the OverlapsWith method in NetworkAddress.

Added new test cases to validate overlapping and non-overlapping scenarios.

Signed-off-by: Ebrahim Nejati <ebrahim@nejati.net>
Comment thread listeners.go Outdated
DearRude and others added 2 commits July 16, 2026 16:09
Improved the hostsOverlap method to handle unspecified addresses more accurately.

Signed-off-by: Ebrahim Nejati <ebrahim@nejati.net>
@steadytao

Copy link
Copy Markdown
Member

This ended up scope-exploding once I looked into the listener and reload lifecycle more closely so I took over the remaining changes to make sure the validation, reload behaviour and tests are correct. Sorry for the sizeable follow-up on what initially looked like a small fix.

@steadytao steadytao added the bug 🐞 Something isn't working label Jul 17, 2026
@steadytao steadytao added this to the v2.11.5 milestone Jul 17, 2026

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could I get one of you to double check this @mholt or @francislavoie?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐞 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confusing behaviour when starting a server on the admin port

3 participants